Skip to content

validator

Override the default validator for determining differences with the cached data.

Classes⚓︎

DictDiffValidator ⚓︎

Default Validator.

Source code in pytest_cache_assert/_check_assert/validator.py
class DictDiffValidator:
    """Default Validator."""

    @staticmethod
    @beartype
    def assertion(
        *, test_data: Any, cached_data: Any, assert_rules: List[AssertRule], path_cache_file: Optional[Path] = None,
    ) -> None:
        """Validate test data against cached data.

        Args:
            test_data: data to compare
            cached_data: data to compare
            assert_rules: list of assert rules to apply
            path_cache_file: optional Path to the cached data

        Raises:
            RichAssertionError: if any assertion comparison fails

        """
        diff_results = diff_with_rules(old_dict=cached_data, new_dict=test_data, assert_rules=assert_rules or [])
        if diff_results.to_dict():
            kwargs = {
                'test_data': test_data,
                'cached_data': cached_data,
                'path_cache_file': path_cache_file,
                'diff_results': diff_results,
            }
            raise RichAssertionError(RichAssertionError.create_message(**kwargs), error_info=kwargs)

Functions⚓︎

assertion staticmethod ⚓︎
assertion(*, test_data, cached_data, assert_rules, path_cache_file=None)

Validate test data against cached data.

PARAMETER DESCRIPTION
test_data

data to compare

TYPE: Any

cached_data

data to compare

TYPE: Any

assert_rules

list of assert rules to apply

TYPE: List[AssertRule]

path_cache_file

optional Path to the cached data

TYPE: Optional[Path] DEFAULT: None

RAISES DESCRIPTION
RichAssertionError

if any assertion comparison fails

Source code in pytest_cache_assert/_check_assert/validator.py
@staticmethod
@beartype
def assertion(
    *, test_data: Any, cached_data: Any, assert_rules: List[AssertRule], path_cache_file: Optional[Path] = None,
) -> None:
    """Validate test data against cached data.

    Args:
        test_data: data to compare
        cached_data: data to compare
        assert_rules: list of assert rules to apply
        path_cache_file: optional Path to the cached data

    Raises:
        RichAssertionError: if any assertion comparison fails

    """
    diff_results = diff_with_rules(old_dict=cached_data, new_dict=test_data, assert_rules=assert_rules or [])
    if diff_results.to_dict():
        kwargs = {
            'test_data': test_data,
            'cached_data': cached_data,
            'path_cache_file': path_cache_file,
            'diff_results': diff_results,
        }
        raise RichAssertionError(RichAssertionError.create_message(**kwargs), error_info=kwargs)

ValidatorType ⚓︎

Bases: Protocol

Validator Interface.

Source code in pytest_cache_assert/_check_assert/validator.py
@runtime_checkable
class ValidatorType(Protocol):
    """Validator Interface."""

    @staticmethod
    def assertion(
        *, test_data: Any, cached_data: Any, assert_rules: List[AssertRule], path_cache_file: Optional[Path] = None,
    ) -> None:
        ...

Functions⚓︎


Last update: August 30, 2023
Created: August 30, 2023